package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;


/**
 * 工程 工单管理 编辑工单 工程施工 施工计划
 * Created by tony on 2018/1/30.
 */

public class EditEngineeringConstructPlanActivity extends Activity implements View.OnClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private final String TAG = EditEngineeringConstructPlanActivity.class.getSimpleName();
    private TextView btn_upload;
    private EditText edt_start, edt_end;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_edit_engineering_construct_plan);


        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        btn_upload = findViewById(R.id.btn_upload);
        edt_start = findViewById(R.id.edt_start);
        edt_end = findViewById(R.id.edt_end);
        tv_title.setText(getResources().getText(R.string.edit_engineering_construct_plan));
        img_back.setOnClickListener(this);
        btn_upload.setOnClickListener(this);

        Intent mIntent = getIntent();
        if (mIntent != null) {
            Bundle mBundle = mIntent.getExtras();
            if (mBundle != null) {
                edt_start.setText(mBundle.getString(ConstantUtil.KEY_1));
                edt_end.setText(mBundle.getString(ConstantUtil.KEY_2));
            }
        }
    }

    private void upload() {
        Intent mIntent = new Intent();
        Bundle mBundle = new Bundle();
        mBundle.putString(ConstantUtil.KEY_1, edt_start.getText().toString().trim());
        mBundle.putString(ConstantUtil.KEY_2, edt_end.getText().toString().trim());
        mIntent.putExtras(mBundle);
        setResult(ConstantUtil.ADD_PRODUCT_LIST, mIntent);
        Toast.makeText(this, "上传成功", Toast.LENGTH_SHORT).show();

        finish();
    }

    @Override
    public void onClick(View view) {
        TextView tv;
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_upload:
                upload();
                break;

        }
    }

}
